#include "BaseOBJ.h"

BaseOBJ::BaseOBJ()
{
    //
}

void BaseOBJ::SetX(int m)
{
    if(m < 0)
        return;
    x = m;
    draw.SetX(x * 64 + hw);

}

void BaseOBJ::SetY(int m)
{
    //if(m <= 0 && m != 0)
    //{
        y = m;
        draw.SetY(y * 64 + hh);
    //}
}


void BaseOBJ::init(Def def)
{
    draw.SetImage(*gImageManager.getResource(def.GetString("image")));
    hw = draw.GetSize().x / 2;
    hh = draw.GetSize().y / 2;
    draw.SetCenter(hw, hh);

    draw.SetX((int)def.GetVal("x") * 64 + hw);
    draw.SetY((int)def.GetVal("y") * 64 + hh);
    x = (int)def.GetVal("x");
    y = (int)def.GetVal("y");
    direction = (int)def.GetVal("rotation");
    draw.SetRotation(direction * 90);
    alive = true;
    solid = (bool)def.GetVal("solid");
    mdef = def;
}

void BaseOBJ::SetDir(int m)
{
    direction = m;
    draw.SetRotation(direction * 90);
}

void BaseOBJ::damage(int dmg)
{
    if((bool)mdef.GetVal("invincible"))
        return;
    mdef.SetVal("health", (int)mdef.GetVal("health") - dmg);
    if((int)mdef.GetVal("health") <= 0)
    {
        alive = false;
    }

}
